﻿#include <stdio.h>
#include "bitmap.h"
#include "canvas.h"
#include "font.h"
#include "vismgr/view.h"
#include "widget/widgets.h"
#include "agg/pixel_formats.h"
#include "agg/platform/agg_platform_support.h"

using namespace visgrph;
using namespace viswidgets;

class theapp : public agg::platform_support
{
public:
	theapp(agg::pix_format_e format, bool flip_y)
		: agg::platform_support(format, flip_y)
	{

	}

	virtual ~theapp()
	{

	}

	virtual void on_draw(void)
	{
		// bind
		bitmap db;
		db.attach(rbuf_window().buf(), rbuf_window().width(), rbuf_window().height(), rbuf_window().stride());
		canvas dc(db);

		dc.clear(color(255, 255, 255, 255));
		dc.hline(10, 20, 50, color(0,0,0,128));
		dc.hline(10, 22, 50, color(128,128,128,255));

		color c(0,255,0,128);
		pen p(8.8f, c);
		p.cap_type(pen_cap_type_round);
		dc.select_object(p);
		dc.line(20, 20, 300, 55);
/*
		canvas dc1(dc);
		canvas dc2(dc1, 10, 10, 30, 30);
		dc2.line(0, 0, 15, 15);
*/

		register_font("Calibri", "c:\\windows\\fonts\\calibri.ttf", 0);
		fontinfo* finfo = register_font(NULL, "c:\\windows\\fonts\\calibriL.ttf", 0);
		register_font("Calibri", "c:\\windows\\fonts\\calibri.ttf", 0);
		register_font(NULL, "c:\\windows\\fonts\\calibrii.ttf", 0, fcs_western, fts_italic);
		register_font(NULL, "d:\\gmsal__.ttf", 0);

		register_font("Times New Roman", "c:\\windows\\fonts\\timesi.ttf", 0, fcs_western, fts_italic);
		register_font("Times New Roman", "c:\\windows\\fonts\\times.ttf", 0);
		fontinfo* fch = register_font(NULL, "c:\\windows\\fonts\\msyh.ttf", 0)->set_default(fcs_eastern);
		register_font(NULL, "c:\\windows\\fonts\\msyh.ttf", 0);
		finfo = register_font(NULL, "d:\\deng.ttf", 0)->set_default(fcs_eastern);
		finfo->set_default(fcs_western);

		font f("DengXian", 15, 15);
		//f.line_scale(0.2);

		form f1(dc);
		f1.setpos(100, 200, 200, 200);
		form f2(f1);
		f2.setpos(150, 50, 100, 100);
		f2.show();
		f1.caption(to_utf8("程序Program Manager").c_str());
		f2.caption("Form 2-1-2-1");
		f1.show();
		view_execute_action();

//		visgrph::qtext_gb18030 txt
//			("对于gPhg已p经过去的20世纪，我们已经没什么可说的了。\n"
//			"让我\t们管中窥豹，对二十一Cent世纪ruy多一些展望。\n"
//			"Fil\te\tEdit View VAssistX Project Build Debug Tool Window Help");
//		txt.setfont(f);
		//txt.wrapping_width(300);
		//txt.wordwrap(true);
		//txt.center();

//		dc.textout(0, 0, txt,
//			visgrph::color(0, 0, 0, 255));

		visgrph::qtext_gb18030 txt1("程序Program Manager long");
		txt1.center();
		dc.rectangle(10, 50, 100, 20, visgrph::color(165, 203, 247, 255));
		dc.textout(10, 50, txt1, visgrph::color(0, 0, 0, 255));
	}
};

int agg_main(int, char*[])
{
	theapp app(pix_format, false);

	// initialize the app
	app.caption("visgraphics test in win32");
	if(app.init(640, 480, 0))
		return app.run();

	return 0;
}